<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="basePath" value="${pageContext.request.contextPath }" />

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>系统登录</title>
	<link rel="stylesheet" href="${basePath}/static/plugins/layui/css/layui.css" media="all">
	<link href="${basePath }/static/plugins/login/style.css" rel="stylesheet" type="text/css" />
	<script src="${basePath }/static/plugins/login/jquery.js"></script>
	<script src="${basePath }/static/plugins/login/cloud.js" type="text/javascript"></script>
	<script>
		var url=parent.window.location.href;
		if(url.indexOf("login")==-1)
		{  
			parent.window.location.href="${basePath}/admin/login";
		}
	
		$(function(){
	    	$('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
			$(window).resize(function(){  
	    	$('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
	    })
	});  
	</script> 
</head>
<body style="background-color:#1c77ac; background-image:url(${basePath}/static/plugins/login/images/light.png); background-repeat:no-repeat; background-position:center top; overflow:hidden;">
	<div id="mainBody">
	  	<div id="cloud1" class="cloud"></div>
	  	<div id="cloud2" class="cloud"></div>
  	</div>  
	<div class="logintop">    
	    <span>欢迎登录</span>    
	    <ul>
	    	<li><a href="javascript:;" id="about">关于</a></li>
	    </ul>    
  	</div>
  	<div class="loginbody">
    	<span class="systemlogo"></span> 
    	<div class="loginbox">
	    	<form method="post" action="javascript:;">
		    	<ul>
		    		<li>
		    			<input required="required" id="adminname" type="text" class="loginuser" placeholder="账户"/>
		    		</li>
		    		<li>
		    			<input required="required" id="pwd" type="password" class="loginpwd" placeholder="密码"/>
		    		</li>
		    		<li>
		    			<input type="button" class="loginbtn" id="submitBtn" value="登录" />
		    		</li>
		    	</ul>
			</form>
	   	</div>
  </div>

	<script src="<%=basePath %>static/plugins/layui/layui.js"></script>
  	<script>
	  layui.use(['layer'], function () {
	      $('#about').click(function () {
			 layer.open({
                 title: '关于'
                 ,content: 'xxx copyright 2018'
                 ,offset: 'rb'
                 ,shade: 0
                 ,shadeClose: false
                 ,anim: 2
                 ,resize: false
                 ,move: false
				 ,closeBtn: 1
                 ,btn: ''
             });
          });

          $('#submitBtn').click(function(){
              console.log('submitBtn')
              submit();
              return false;
          });

          $(window).keydown(function(event){
              if(event.keyCode == 13){
                  submit();
                  return false;
              }
          });

          var submit = function(){
              $.ajax({
                  url: '${basePath}/admin/login/in',
                  type: 'post',
                  dataType: 'json',
                  data: {
                      username: $('#adminname').val(),
                      password: $('#pwd').val()
                  },
                  success: function(resp){
                      console.log(resp);
                      if(resp.code==10000){
                          window.location.href = "${basePath}/admin/index";
                      }else{
                          layer.alert(resp.msg);
                      }
                  },
                  error: function(xhr){
                      console.log(xhr);
                      layer.alert('网络连接异常')
                  }
              });
          }
      });
	</script>
</body>
</html>